/*******************************************************************************
 * Copyright (c) 2011 Google, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Google, Inc. - initial API and implementation
 *******************************************************************************/
package com.zgw.his.design.model.property.edit;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.wb.internal.core.model.property.Property;
import org.eclipse.wb.internal.core.model.property.editor.PropertyEditor;
import org.eclipse.wb.internal.core.model.property.editor.TextDialogPropertyEditor;
import org.eclipse.wb.internal.core.xml.model.property.GenericProperty;

/**
 * {@link PropertyEditor} for selecting model of {@link Object} in XWT.
 * 
 * @author scheglov_ke
 * @coverage XWT.model.property.editor
 */
public final class ObjectPropertyEditor extends TextDialogPropertyEditor {
	// //////////////////////////////////////////////////////////////////////////
	//
	// Instance
	//
	// //////////////////////////////////////////////////////////////////////////
	public static final PropertyEditor INSTANCE = new ObjectPropertyEditor();

	private ObjectPropertyEditor() {
	}

	@Override
	protected String getText(Property property) throws Exception {
		GenericProperty property_ = (GenericProperty) property;
		return property_.getValue() != null ? property_.getValue().toString()
				: "";
	}

	// //////////////////////////////////////////////////////////////////////////
	//
	// Editing
	//
	// //////////////////////////////////////////////////////////////////////////
	@Override
	protected void openDialog(Property property_) throws Exception {
		GenericProperty property = (GenericProperty) property_;
		TestDialog dlg = new TestDialog(Display.getDefault().getActiveShell(),
				SWT.NONE, property.getValue());
		property.setValue(dlg.open());
	}

}
